package com.come4loves.game.module.fight.action;

import java.util.ArrayList;
import java.util.List;

import com.come4loves.game.module.battle.helper.PBConvertHelper;
import com.come4loves.game.module.fight.constants.CardLocation;
import com.come4loves.game.module.fight.model.Card2Location;
import com.come4loves.game.module.fight.model.FightCard;
import com.come4loves.game.proto.BattleProto;


/**
 * 牌进入牌堆动作
 * @author jerry
 *
 */
public class CardToLocationAction extends Action {
	private List<Card2Location> locations;
	private Long actorId;
	public CardToLocationAction(List<Card2Location> locations) {
		super(0);
		this.locations = locations;
	}
	public CardToLocationAction(Card2Location location) {
		super(0);
		this.locations = new ArrayList<Card2Location>();
		this.locations.add(location);
	}
	public CardToLocationAction(List<Card2Location> locations, Long actorId) {
		super(0);
		this.locations = locations;
		this.actorId = actorId;
	}
	
	public static CardToLocationAction createFromCard(FightCard fightCard,CardLocation cardLocation ){
		List<Card2Location> locations = new ArrayList<Card2Location>();
		Card2Location location = new Card2Location(fightCard, cardLocation);
		locations.add(location );
		return new CardToLocationAction(locations);
	}
	public static CardToLocationAction createFromCard(FightCard fightCard,CardLocation cardLocation,Long actorId ){
		List<Card2Location> locations = new ArrayList<Card2Location>();
		Card2Location location = new Card2Location(fightCard, cardLocation);
		locations.add(location );
		return new CardToLocationAction(locations, actorId);
	}
	@Override
	public String toString(){
		StringBuffer sbBuffer = new StringBuffer();
		for (Card2Location card2Location : locations) {
			sbBuffer.append(card2Location.toString());
		}
		return this.getClass().getSimpleName() + "--" + sbBuffer.toString()+"--";
	}
	
	
	public com.google.protobuf.GeneratedMessage.Builder<?> toProtocolBufferBuilder() {
		BattleProto.CardToLocationAction.Builder builder = BattleProto.CardToLocationAction.newBuilder();
		for (Card2Location card2Location : locations) {
			builder.addLoactions(PBConvertHelper.cardLocationConvert(card2Location, true,this.actorId));
		}
		return builder;
	}
	
	
}
